<template>
    <div class="contact-table-list">
        <el-table
                ref="contactTable"
                :data="tableData"
                :height="tableHeight"
                border
                style="width: 100%"
                :row-class-name="tableRowClassName"
                @selection-change="handleSelectionChange"
                :default-sort="defaultSort">
            <el-table-column
                    type="selection"
                    show-overflow-tooltip
                    width="50">
            </el-table-column>
            <el-table-column
                    prop="number"
                    label="编号"
                    width="95"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="JGName"
                    label="机构名称"
                    width="250"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="name"
                    label="姓名"
                    width="95"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="sex"
                    label="性别"
                    width="80"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="job"
                    label="职务"
                    width="95"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="telephone"
                    label="手机"
                    width="125"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="workPhone"
                    label="办公电话"
                    width="130"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="importantLevel"
                    label="重要等级"
                    width="105"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="followStatus"
                    label="跟进状态"
                    width="105"
                    :filters="followStatusFilter"
                    :filter-method="filterFollowStatus"
                    filter-placement="bottom-end">
                <template slot-scope="scope">
                    <el-tag :type="followStatusType(scope.row.followStatus)" close-transition>
                        {{scope.row.followStatus}}
                    </el-tag>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button
                            size="mini"
                            @click="handleEdit(scope.$index, scope.row)">编辑
                    </el-button>
                    <el-button
                            size="mini"
                            type="danger"
                            @click="handleDelete(scope.$index, scope.row)">删除
                    </el-button>
                    <el-button size="mini" type="primary" @click="handleLook(scope.$index, scope.row)">查看</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
    export default {
        name: "ContactTableList",
        props: {
            tableHeight: {
                required: false,
                type: String,
                default: () => {
                    return "550";
                }
            },
            defaultSort: {
                required: false,
                type: Object,
                default: () => {
                    return {prop: 'number', order: 'descending'};
                }
            }
        },
        computed: {
            followStatusFilter() {
                return [{text: '未处理', value: '未处理'}, {text: '有效', value: '有效'}, {text: '无效', value: '无效'}];
            },
        },
        data() {
            return {
                multipleSelection: [],
                tableData: [{
                    number: "10021",
                    JGName: "南阳医学高等专科学校图书馆",
                    name: "李亚琴",
                    sex: "女",
                    job: "馆长",
                    telephone: "18553386579",
                    workPhone: "0898-313508831",
                    importantLevel: "一般",
                    followStatus: "有效"
                },{
                    number: "10021",
                    JGName: "南阳医学高等专科学校图书馆",
                    name: "李亚琴",
                    sex: "女",
                    job: "馆长",
                    telephone: "18553386579",
                    workPhone: "0898-313508831",
                    importantLevel: "一般",
                    followStatus: "有效"
                },{
                    number: "10021",
                    JGName: "南阳医学高等专科学校图书馆",
                    name: "李亚琴",
                    sex: "女",
                    job: "馆长",
                    telephone: "18553386579",
                    workPhone: "0898-313508831",
                    importantLevel: "一般",
                    followStatus: "有效"
                },{
                    number: "10021",
                    JGName: "南阳医学高等专科学校图书馆",
                    name: "李亚琴",
                    sex: "女",
                    job: "馆长",
                    telephone: "18553386579",
                    workPhone: "0898-313508831",
                    importantLevel: "一般",
                    followStatus: "有效"
                },{
                    number: "10021",
                    JGName: "南阳医学高等专科学校图书馆",
                    name: "李亚琴",
                    sex: "女",
                    job: "馆长",
                    telephone: "18553386579",
                    workPhone: "0898-313508831",
                    importantLevel: "非常重要",
                    followStatus: "有效"
                },{
                    number: "10021",
                    JGName: "南阳医学高等专科学校图书馆",
                    name: "李亚琴",
                    sex: "女",
                    job: "馆长",
                    telephone: "18553386579",
                    workPhone: "0898-313508831",
                    importantLevel: "重要",
                    followStatus: "有效"
                },{
                    number: "10021",
                    JGName: "南阳医学高等专科学校图书馆",
                    name: "李亚琴",
                    sex: "女",
                    job: "馆长",
                    telephone: "18553386579",
                    workPhone: "0898-313508831",
                    importantLevel: "一般",
                    followStatus: "有效"
                },{
                    number: "10021",
                    JGName: "南阳医学高等专科学校图书馆",
                    name: "李亚琴",
                    sex: "女",
                    job: "馆长",
                    telephone: "18553386579",
                    workPhone: "0898-313508831",
                    importantLevel: "一般",
                    followStatus: "未处理"
                },{
                    number: "10021",
                    JGName: "南阳医学高等专科学校图书馆",
                    name: "李亚琴",
                    sex: "女",
                    job: "馆长",
                    telephone: "18553386579",
                    workPhone: "0898-313508831",
                    importantLevel: "一般",
                    followStatus: "无效"
                },{
                    number: "10021",
                    JGName: "南阳医学高等专科学校图书馆",
                    name: "李亚琴",
                    sex: "女",
                    job: "馆长",
                    telephone: "18553386579",
                    workPhone: "0898-313508831",
                    importantLevel: "一般",
                    followStatus: "有效"
                }]
            }
        },
        methods: {
            followStatusType(followStatus) {
                switch (followStatus) {
                    case '有效':
                        return 'success';
                    case '无效':
                        return 'danger';
                    case '未处理':
                        return 'primary';
                }
            },
            /**
             * 编辑
             * @param index
             * @param row
             */
            handleEdit(index, row) {
                console.log(index, row);
            },
            /**
             * 删除
             * @param index
             * @param row
             */
            handleDelete(index, row) {
                console.log(index, row);
            },
            /**
             * 查看
             * @param index
             * @param row
             */
            handleLook(index, row) {
                console.log(index, row);
            },
            /**
             * 状态过滤
             * @param value
             * @param row
             * @returns {boolean}
             */
            filterFollowStatus(value, row) {
                return row.followStatus === value;
            },
            /**
             * 行背景色处理
             * @param row
             * @param rowIndex
             * @returns {string}
             */
            tableRowClassName({row, rowIndex}) {
                if (row.followStatus === '无效') {
                    return 'danger-row';
                } else if (row.followStatus === '有效') {
                    return 'success-row';
                } else if (row.followStatus === '未处理') {
                    return 'default-row';
                }
                return '';
            },
            /**
             * 选中行处理
             * @param val
             */
            handleSelectionChange(val) {
                this.multipleSelection = val;
            }
        }
    }
</script>

<style lang="scss">
    .contract-table-list {

    }
</style>